package com.hzhq.contract.convert.method;

import com.hzhq.contract.bean.dto.AttachmentDTO;
import com.hzhq.contract.bean.dto.CompanyDTO;
import com.hzhq.contract.bean.dto.ContractStatusDTO;
import com.hzhq.contract.bean.entity.Attachment;
import com.hzhq.contract.bean.entity.Company;
import com.hzhq.contract.bean.entity.ContractStatus;
import com.hzhq.contract.bean.vo.AttachmentVO;
import com.hzhq.contract.bean.vo.CompanyVO;
import com.hzhq.contract.bean.vo.ContractStatusVO;
import com.hzhq.contract.convert.AttachmentConvertBasic;
import com.hzhq.contract.convert.CompanyConvertBasic;
import com.hzhq.contract.convert.ContractStatusConvertBasic;
import com.hzhq.contract.status.DefaultValue;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: hzhq1255
 * @mail: hzhq1255@163.com
 * @date: 2021/4/20 12:53
 * @desc:
 */
public class ContractConvertMethod {


    public static BigDecimal getCurrentAmount(List<ContractStatus> statusList) {
        BigDecimal amount = new BigDecimal(0);
        for (ContractStatus status : statusList) {
            if (status != null && status.getDeleted().equals(DefaultValue.NOT_DELETED)) {
                amount = amount.add(status.getPayment());
            }
        }
        return amount;
    }

    public static String getContactInfo(String person, String phone) {
        return person + '/' + phone;
    }


    public static String companiesDtoToString(List<CompanyDTO> companyDTOS) {
        StringBuilder companies = new StringBuilder();
        if (companyDTOS == null) {
            return null;
        }
        for (CompanyDTO s : companyDTOS) {
            if (s == null) {
                continue;
            }
            companies.append(s.getCompanyName()).append(",");
        }
        if (companies.length() == 0) {
            return "";
        }
        companies.delete(companies.lastIndexOf(","), companies.length());
        return companies.toString();
    }


    public static List<CompanyDTO> companiesToCompaniesDto(List<Company> companies) {
        return companies == null ? null : companies.stream().map(CompanyConvertBasic.INSTANCE::poToDto).collect(Collectors.toList());
    }

    public static List<Company> companiesDtoToCompanies(List<CompanyDTO> companiesDto) {
        return companiesDto == null ? null : companiesDto.stream().map(CompanyConvertBasic.INSTANCE::dtoToPo).collect(Collectors.toList());
    }

    public static List<CompanyVO> companiesDtoToCompaniesVo(List<CompanyDTO> companiesDto) {
        return companiesDto == null ? null : companiesDto.stream().map(CompanyConvertBasic.INSTANCE::dtoToVo).collect(Collectors.toList());
    }

    public static List<CompanyDTO> companiesVoToCompaniesDto(List<CompanyVO> companiesVo) {
        return companiesVo == null ? null : companiesVo.stream().map(CompanyConvertBasic.INSTANCE::voToDto).collect(Collectors.toList());
    }

    public static List<AttachmentDTO> attachmentsToAttachmentsDto(List<Attachment> attachments) {
        return attachments == null ? null : attachments.stream().map(AttachmentConvertBasic.INSTANCE::poToDto).collect(Collectors.toList());
    }

    public static List<Attachment> attachmentsDtoToAttachments(List<AttachmentDTO> attachmentsDto) {
        return attachmentsDto == null ? null : attachmentsDto.stream().map(AttachmentConvertBasic.INSTANCE::dtoToPo).collect(Collectors.toList());
    }

    public static List<AttachmentDTO> attachmentsVoToAttachmentsDto(List<AttachmentVO> attachmentsVo) {
        return attachmentsVo == null ? null : attachmentsVo.stream().map(AttachmentConvertBasic.INSTANCE::voToDto).collect(Collectors.toList());
    }

    public static List<AttachmentVO> attachmentsDtoToAttachmentsVo(List<AttachmentDTO> attachmentsDto) {
        return attachmentsDto == null ? null : attachmentsDto.stream().map(AttachmentConvertBasic.INSTANCE::dtoToVO).collect(Collectors.toList());
    }

    public static List<ContractStatusDTO> statusesToStatusesDto(List<ContractStatus> statuses) {
        return statuses == null ? null : statuses.stream().map(ContractStatusConvertBasic.INSTANCE::poToDto).collect(Collectors.toList());
    }

    public static List<ContractStatus> statusesDtoToStatuses(List<ContractStatusDTO> statusesDto) {
        return statusesDto == null ? null : statusesDto.stream().map(ContractStatusConvertBasic.INSTANCE::dtoToPo).collect(Collectors.toList());
    }

    public static List<ContractStatusDTO> statusesVoToStatusesDto(List<ContractStatusVO> statusesVo) {
        return statusesVo == null ? null : statusesVo.stream().map(ContractStatusConvertBasic.INSTANCE::voToDto).collect(Collectors.toList());
    }

    public static List<ContractStatusVO> statusesDtoToStatusesVo(List<ContractStatusDTO> statusesDto) {
        return statusesDto == null ? null : statusesDto.stream().map(ContractStatusConvertBasic.INSTANCE::dtoToVo).collect(Collectors.toList());
    }

}
